﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;
using DIST.LR.ZHJG.DataModel;
using DIST.LR.ZHJG.WCFServices.EntityDataManageService;
using System.Collections.Generic;

namespace DIST.LR.ZHJG.Pgybc
{
    public class Zbgl_KPIORIGINModel : INotifyPropertyChanged
    {
        protected EntityDataManageServiceClient client = DIST.LR.ZHJG.WCFServices.CommonServices.WCFService;

        public Zbgl_KPIORIGINModel()
        {
            GetKPIOriginSource();
        }

        public void GetKPIOriginSource()
        {
            string strSql = string.Format("from TKPIORIGIN order by ID asc");
            client.SelectTkpiOriginCompleted += new EventHandler<SelectTkpiOriginCompletedEventArgs>(client_SelectTkpiOriginCompleted);
            client.SelectTkpiOriginAsync(strSql, "0");
        }

        void client_SelectTkpiOriginCompleted(object sender, SelectTkpiOriginCompletedEventArgs e)
        {
            int count = Convert.ToInt32(e.Result.Count);
            if (count == 1) return;

            IList<TKPIORIGIN> lst = e.Result as IList<TKPIORIGIN>;
            ObservableCollection<KPIOrigin> _kpiOriginInfo = new ObservableCollection<KPIOrigin>();
            KPIOrigin kpiOrigin;
            foreach (TKPIORIGIN item in lst)
            {
                kpiOrigin = new KPIOrigin();
                kpiOrigin.KPIORIGINComputeSql = item.COMPUTESQL;
                kpiOrigin.KPIORIGINConstring = item.CONSTRING;
                kpiOrigin.KPIORIGINGetType = item.GETTYPE;
                kpiOrigin.KPIORIGINId = item.ID;
                kpiOrigin.KPIORIGINName = item.NAME;
                kpiOrigin.KPIORIGINUpdateCycle = item.UPDATECYCLE;
                kpiOrigin.KPIORIGINUpdateTime = item.UPDATETIME;
                kpiOrigin.KPIORIGINValue = item.VALUE;
                _kpiOriginInfo.Add(kpiOrigin);
            }
            KpiOriginInfo = _kpiOriginInfo;
        }

        private ObservableCollection<KPIOrigin> kpiOriginInfo;
        public ObservableCollection<KPIOrigin> KpiOriginInfo
        {
            get { return this.kpiOriginInfo; }
            set
            {
                if (this.kpiOriginInfo != value)
                {
                    this.kpiOriginInfo = value;
                    this.OnPropertyChanged("KpiOriginInfo");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
